/**
 * Created by qunxing.du on 2016/8/12.
 * Copyright 2016 汉威.智慧环保事业部 Limited.
 * All rights reserved.
 */
package com.hw.one.collect.pollution.server;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import io.netty.handler.codec.LengthFieldPrepender;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;

/**
 * 通道注册
 */
public class CustomChannelInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ch.pipeline()
                .addLast("server-logging-handler",new LoggingHandler(LogLevel.DEBUG))
                .addLast("server-length-decoder",new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE,0,4,0,4))
                .addLast("server-string-decoder",new StringDecoder())
                .addLast("server-length-encoder",new LengthFieldPrepender(4,false))
                .addLast("server-string-encoder",new StringEncoder())
                .addLast("authen-handler",new AuthenHandler())
                .addLast("rawdata-handler",new PollutionRawDataHandler())
                .addLast("transformdata-handler",new PollutionTransformDataHandler());
//                .addLast("custom-handler",new CustomServerHandler())


    }
}
